<extend name="./ljfbase" />
    <block name="main">
        <script src="__PUBLIC__/js/jquery.min.js"></script>
        <div class="container mt20">
            <div class="col-md-10 col-md-offset-1">
                <form action="{:U(toedit)}" method="post">
                    <input type="hidden" name="say_id" value="{$say.id}" />
                    编辑说说：
                    <textarea class="form-control" name="content" placeholder="请输入说说内容">{$say.content}</textarea><br>
                    选择图片：<input type="file" name="pic[]" multiple="multiple" id="pic"/><br>
                    <div>
                        <ul id="pic_tmp">
                            <foreach name="say.pic" item="item">
                                <li>
                                    <img src="__PUBLIC__/uploads/{$item[path]}" width="100" alt="说说配图">
                                    <input type="hidden" name="oldimg[]" value="{$item[id]}" />
                                </li>
                            </foreach>
                        </ul>
                    </div>
                    <button class="btn btn-primary" type="submit">保存</button>
                    <a class="btn btn-default" href="{:U('index')}">取消</a>
                </form>
            </div>
        </div>
        

        <script>
            //ajax上传图片
            $("#pic").on('change',function(){
                var formData = new FormData();
                $.each($('#pic')[0].files, function(i, file) {
                    formData.append('upload_file[]', file);
                });
            
                $.ajax({
                    url: '{:U("uploadimg")}',
                    type: 'POST',
                    cache: false,
                    data: formData,
                    dataType: "json",
                    processData: false,
                    contentType: false,
                    success: function(rs){
                        // debugger;
                        var imgbox = $('#pic_tmp');
                        var lis = "";
                        $.each(rs.info,function(i,n){
                            lis += '<li><img width="100" src="__PUBLIC__/uploads/' + n.savepath + n.savename +'"><input class="imgpath" type="hidden" name="img[]" value="'+ n.savepath + n.savename +'"></li>' ;
                        });
                        imgbox.append(lis);
                        $('#pic').val(''); // 清空选择的照片
                    }
                });

            });
        </script>
    </block>